package com.farmer.controller;

import com.farmer.pojo.Notice;
import com.farmer.service.NoticeService;
import com.farmer.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("notice")
@CrossOrigin
public class NoticeController {
    @Autowired
    private NoticeService noticeService;


    @PostMapping("add")
    public Result add(@RequestHeader String token,@RequestBody Notice notice) {
        Result result =noticeService.add(token,notice);
        return result;
    }

    @DeleteMapping("delete")
    public Result delete(@RequestParam Integer id) {
        Result result = noticeService.delete(id);
        return result;
    }

    @PutMapping("update")
    public Result update(@RequestBody Notice notice) {
        Result result = noticeService.update(notice);
        return result;
    }

    @GetMapping("getById")
    public Result getById(@RequestParam Integer id) {
        Result result = noticeService.getById(id);
        return result;
    }
    
    @GetMapping("getAll")
    public Result getAll() {
        Result result = noticeService.getAll();
        return result;
    }


    @GetMapping("getByTitleLike")
    public Result getByTitleLike(@RequestParam String title){
        Result result = noticeService.getByTitleLike(title);
        return result;
    }

    @DeleteMapping("delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        Result result = noticeService.deleteBatch(ids);
        return result;
    }
    @GetMapping("page")
    public Result page(@RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        Result result=noticeService.page(pageNum,pageSize);
        return result;
    }
}
